home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / packages / underline.el < prev    next >
Encoding:
Text File  |  1995-03-25  |  3.7 KB  |  112 lines

  1. ;;; underline.el --- insert/remove underlining (done by overstriking) in Emacs.
  2.  
  3. ;; Copyright (C) 1985, 1993 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: wp
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; Commentary:
  25.  
  26. ;; This package deals with the primitive form of underlining
  27. ;; consisting of prefixing each character with "_\^h".  The entry
  28. ;; point `underline-region' performs such underlining on a region.
  29. ;; The entry point `ununderline-region' removes it.
  30.  
  31. ;;; Code:
  32.  
  33. ;;;###autoload
  34. (defun underline-region (start end)
  35.   "Underline all nonblank characters in the region.
  36. Works by overstriking underscores.
  37. Called from program, takes two arguments START and END
  38. which specify the range to operate on."
  39.   (interactive "*r")
  40.   (save-excursion
  41.     (let ((end1 (make-marker)))
  42.       (move-marker end1 (max start end))
  43.       (goto-char (min start end))
  44.       (while (< (point) end1)
  45.     (or (looking-at "[_\^@- ]")
  46.         (insert "_\b"))
  47.     (forward-char 1)))))
  48.  
  49. ;;;###autoload
  50. (defun ununderline-region (start end)
  51.   "Remove all underlining (overstruck underscores) in the region.
  52. Called from program, takes two arguments START and END
  53. which specify the range to operate on."
  54.   (interactive "*r")
  55.   (save-excursion
  56.     (let ((end1 (make-marker)))
  57.       (move-marker end1 (max start end))
  58.       (goto-char (min start end))
  59.       (while (re-search-forward "_\b\\|\b_" end1 t)
  60.     (delete-char -2)))))
  61.  
  62. ;;;###autoload
  63. (defun unoverstrike-region (start end)
  64.   "Remove all overstriking (character-backspace-character) in the region.
  65. Called from program, takes two arguments START and END which specify the
  66. range to operate on."
  67.   (interactive "*r")
  68.   (save-excursion
  69.     (let ((end1 (make-marker)))
  70.       (move-marker end1 (max start end))
  71.       (goto-char (min start end))
  72.       (while (re-search-forward "\\(.\\)\b\\1" end1 t)
  73.     (delete-char -2)))))
  74.  
  75. ;;;###autoload
  76. (defun overstrike-region (start end)
  77.   "Overstrike (character-backspace-character) all nonblank characters in
  78. the region. Called from program, takes two arguments START and END which
  79. specify the range to operate on."
  80.   (interactive "*r")
  81.   (save-excursion
  82.     (let ((end1 (make-marker)))
  83.       (move-marker end1 (max start end))
  84.       (goto-char (min start end))
  85.       (while (< (point) end1)
  86.     (or (looking-at "[_\^@- ]")
  87.         (insert (char-after (point)) 8))
  88.     (forward-char 1)))))
  89.  
  90. ;;;###autoload
  91. (defun ununderline-and-unoverstrike-region (start end)
  92.   "Remove underlining and overstriking in the region.  Called from a program,
  93. takes two arguments START and END which specify the range to operate on."
  94.   (interactive "*r")
  95.   (save-excursion
  96.     ;; This is a piece of nuke-nroff-bs from standard `man.el'.
  97.     (goto-char (point-min))
  98.     (while (search-forward "\b" (max start end) t)
  99.       (let* ((preceding (char-after (- (point) 2)))
  100.          (following (following-char)))
  101.     (cond ((= preceding following)
  102.            ;; x\bx
  103.            (delete-char -2))
  104.           ((= preceding ?\_)
  105.            ;; _\b
  106.            (delete-char -2))
  107.           ((= following ?\_)
  108.            ;; \b_
  109.            (delete-region (1- (point)) (1+ (point)))))))))
  110.  
  111. ;;; underline.el ends here
  112.